<!doctype html>
<html>

	<head>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta charset="UTF-8" />
		<title>我的订单-全部订单</title>
		<link rel="stylesheet" type="text/css" href="css/personalData.css" />
		<link rel="stylesheet" type="text/css" href="css/svg/font.css" />
		<script type="text/javascript" src="js/jquery-2.1.4.min.js" ></script>
		<script type="text/javascript">
			window.onload = function() {
				document.documentElement.style.fontSize = document.documentElement.clientWidth / 320 * 20 + 'px';
				window.onresize = function() {
					document.documentElement.style.fontSize = document.documentElement.clientWidth / 320 * 20 + 'px';
				};
			};
		</script>
	</head>

	<body>
		<!--我的订单header开始-->
		<header class='wdddbox'>
			<a href="javascript:;" id="goMy">< 我的订单</a>
			<i class='icon-search'></i>
			<img src='img/dfkdd.jpg' class='dfkdd'>
		</header>
		<!--我的订单header结束-->

		<!--我的订单内容开始-->
		<ul class='wdddnr'>
			<a href="javascript:;"><li>全部</li></a>
			<a href="../1603B-taobao/NOpayment.html"><li>待付款</li></a>
			<a href="javascript:;"><li>待发货</li></a>
			<a href="javascript:;"><li>待收货</li></a>
			<a href="javascript:;"><li>待评价</li></a>
		</ul>
		<!--我的订单内容结-->

		<!--我的订单footer开始-->
		<footer class="orderList">
			
		</footer>
		<!--我的订单footer结束-->
		
		<!--删除提示盒子开始-->
		<div id="deleteBig"></div>
		<div id="deleteBox">
			<article>确认删除订单？</article>
			<p>删除之后可以从电脑端订单回收站恢复</p>
			<aside>
				<a href="javascript:;" id="cancel">取消</a>
				<a href="javascript:;" id="sure">确定</a>
			</aside>
		</div>
		<!--删除提示盒子结束-->
	</body>
	<script>
		//点击返回my我的页面
		$("#goMy").click(function() {
			window.location.href = 'my.html';
		})
	
		//读取全部订单的商品列表Ajax
		var comberBID = 0,//订单的商品的索引值
			comberID = [],//订单的商品的id数组
			comberCount = [],//订单的商品的数量数组
			comberOrderTime = [];//订单的创建时间数组
		$.ajax({
			type: "post",
			url: "http://192.168.1.100/supermarket/data/get_commodity_order.php",
			data: {
				'user_phone': localStorage.user_phone
			},
			async: true,
			dataType: "jsonp",
			jsonp: "callback",
			jsonpCallback: "success_jsonpCallback",
			success: function(data) {
//				debugger
				for(var i=0; i<data.length; i++){
					comberID.push(data[i].commodity_id);
					comberCount.push(data[i].count);
					comberOrderTime.push(data[i].order_time);
				}
				//如果当前购物车商品数组有商品时则调用函数
				if(data.length > 0){
					go();
				}else{
					return;
				}
			},
			error: function(data) {}
		})
//		console.log(commID)
//		console.log(commOrderTime)

		//封装获取订单Ajax里全部商品的详情
		function go(){
			$.ajax({
				type: "post",
				url: "http://192.168.1.100/supermarket/data/get_commodity_info.php",
				async: true,
				data: {
					'id': comberID[comberBID]
				},
				dataType: 'jsonp',
				jsonp: 'callback',
				jsonpCallback: 'success_JsonpCallback',
				success: function(data) {
//					debugger;
					var str = '<ul><li><img src="img/wdtm.jpg"> 天猫超市 ><a>交易成功</a></li><li class="GoThisOrder"><a href="../1603B-taobao/OrderDetails.html?id=' +
					comberID[comberBID] + '&ThisCount=' +
					comberCount[comberBID] + '&ThisDate=' +
					comberOrderTime[comberBID] + '"><img src="http://192.168.1.100/supermarket/img/' +
					data.img + '"/></a><p>' +
					data.name + '</p><p><span>￥' +
					data.price +'</span><span>X' +
					comberCount[comberBID] +'</span></p></li><li>共<span>' +
					comberCount[comberBID] +'</span>件商品 共计:<a id="TotalPrice">￥' +
					comberCount[comberBID]*data.price +'</a><a>(含运费 ￥0.00)</a></li><li><a href="javascript:;" id="deleteOrder" thisTime="' +
					comberOrderTime[comberBID] +'" thisID="' +
					comberID[comberBID] +'" >删除订单</a>\
					<a id="evaluate">评价</a></li></ul>';
					$('.orderList').append(str);
					//判断订单有几个，如果只有1个订单则不调用ajax函数，如果>1则调用
					if(comberBID == comberID.length - 1){}else{
						comberBID++;
						go();
					}
					//console.log(commID.length);
				},
				error: function(data) {}
			})
		}
		
		//点击删除订单弹出提示盒子
		var thisTime = '',
			thisId = '',
			thisPhone = '';
		$('.orderList').delegate('#deleteOrder','click',function(){
			thisTime = $(this).attr('thisTime');
			thisId = $(this).attr('thisID');				
				$.ajax({
					type: "post",
					url: "http://192.168.1.100/supermarket/data/my_commodity_delete_order.php",
					data: {
						'order_time': thisTime,
						'commodity_id':	thisId,
						'user_phone': localStorage.user_phone
					},
					async: true,
					dataType: "jsonp",
					jsonp: "callback",
					jsonpCallback: "success_jsonpCallback",
					success: function(data) {
//						debugger;
						window.location.reload();
					},
					error: function(data) {}
				})
		
		})
		
		
		
//点击评价商品
		$('.orderList').delegate('#evaluate','click',function(){
			sessionStorage.thisImgSrc = $(this).parent().parent().find('.GoThisOrder').find('img').attr('src');
			sessionStorage.thisId = $(this).parent().find('#deleteOrder').attr('thisid');
			window.location.href="pingjia.html";
		})
	</script>





</html>